package com.cqs.leetcode.math;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * lixw
 * 2021/11/4
 **/
public class ValidPerfectSquare367 {
    public boolean isPerfectSquare(int num) {
        int left = 1, right = Integer.MAX_VALUE;
        while (left <= right) {
            int mid = (right-left )/2 + (left);
            if (num / mid  > mid ) {
                left = mid + 1;
            }else if (num / mid == mid ) {
                return mid * mid == num;
            }else {
                right = mid - 1;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        ValidPerfectSquare367 v = new ValidPerfectSquare367();
        int[] cases = {16,1,3,5,8,9,16,Integer.MAX_VALUE};
        for (int c: cases) {
            System.out.println(c + " ---- " + v.isPerfectSquare(c));
        }
    }
}
